package com.rran.study.designpattern.behavioral.strategy;


import com.rran.study.designpattern.behavioral.strategy.enums.PayEnums;
import com.rran.study.designpattern.behavioral.strategy.factory.PayStretegyRefleftEnumFactory;
import com.rran.study.designpattern.behavioral.strategy.model.PayContext;
import com.rran.study.designpattern.behavioral.strategy.strategy.PayStrategy;

import java.math.BigDecimal;

/**
 * 通过枚举反射实现
 * 工厂采用枚举反射出对应的策略strategy,新增策略只需增加枚举和策略类即可,符合开闭原则
 */
public class StrategyEnumRefleftApplication {

    public static void main(String[] args) throws Exception {

        PayContext payContext = new PayContext();
        payContext.setName("Rran");
        payContext.setPrice(new BigDecimal(200));
        payContext.setStrategy(PayEnums.ALI);

        PayStrategy payStrategy = PayStretegyRefleftEnumFactory.getPayStrategy(payContext.getStrategy().name());
        payStrategy.pay(payContext);
    }


}
